package com.winhxd.b2c.order.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.order.condition.OrderUserManagementQueryCondition;
import com.winhxd.b2c.common.domain.order.vo.OrderInfoDetail4UserManagementVO;
import com.winhxd.b2c.order.dao.OrderInfoMapper;
import com.winhxd.b2c.order.service.OrderUserManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 用户管理中订单相关接口
 * @author suhaochan
 * @date 2019/1/10 13:43:24
 */
@Service
public class OrderUserManagementServiceImpl implements OrderUserManagementService {
	
	@Autowired
	OrderInfoMapper orderInfoMapper;
	
	@Override
	public PagedList<OrderInfoDetail4UserManagementVO> findDistributorOrder(
			OrderUserManagementQueryCondition condition) {
		PagedList<OrderInfoDetail4UserManagementVO> result = new PagedList<OrderInfoDetail4UserManagementVO>();
		Page page = PageHelper.startPage(condition.getPageNo(), condition.getPageSize());
		//分销商做为会员，自已下的订单信息--二级分销商和一级分销商也是会员，二级分销商和一级分销商的上级分销为自己
		List<OrderInfoDetail4UserManagementVO> list = orderInfoMapper.selectMemberOrderInfoByParams(condition);
		result.setPageNo(condition.getPageNo());
		result.setPageSize(condition.getPageSize());
		result.setTotalRows(page.getTotal());
		result.setData(list);
		return result;
	}

	@Override
	public PagedList<OrderInfoDetail4UserManagementVO> findDistributorMemberOrder(
			OrderUserManagementQueryCondition condition) {
		PagedList<OrderInfoDetail4UserManagementVO> result = new PagedList<OrderInfoDetail4UserManagementVO>();
		Page page = PageHelper.startPage(condition.getPageNo(), condition.getPageSize());
		//分销商旗下会员自动下过的订单--仅算与分销商产生绑定关系的会员订单，不算一级分销商旗下二级分销商的订单
		List<OrderInfoDetail4UserManagementVO> list = orderInfoMapper.selectDistributorMemberOrder(condition);
		result.setPageNo(condition.getPageNo());
		result.setPageSize(condition.getPageSize());
		result.setTotalRows(page.getTotal());
		result.setData(list);
		return result;
	}

	@Override
	public PagedList<OrderInfoDetail4UserManagementVO> findMemberOrder(OrderUserManagementQueryCondition condition) {
		PagedList<OrderInfoDetail4UserManagementVO> result = new PagedList<OrderInfoDetail4UserManagementVO>();
		Page page = PageHelper.startPage(condition.getPageNo(), condition.getPageSize());
		//查询会员自主下过的全部的订单信息
		List<OrderInfoDetail4UserManagementVO> list = orderInfoMapper.selectMemberOrderInfoByParams(condition);
		result.setPageNo(condition.getPageNo());
		result.setPageSize(condition.getPageSize());
		result.setTotalRows(page.getTotal());
		result.setData(list);
		return result;
	}

}
